import {Modal} from 'antd';
import {WeaSearchGroup, WeaFormItem} from 'ecCom';
import {WeaSwitch} from 'comsMobx';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

//表单验证
export const  onCheck = (form, func) => {
  form.validateForm().then(f=>{
    if(f.isValid){
      func && typeof func == 'function' && func();
    }else{
      f.showErrors();
    }
  });
}

export const setModal = (content) => {
  Modal.warning({
    title: getLabel(15172,'系统提示'),
    content: content,
  });
}

//信息确认
export const doConfirm = (content, func) => {//确认信息， 方法， 方法参数
  Modal.confirm({
    title: `${getLabel(131329,'信息确认')}`,
    content: content,
    okText: `${getLabel(826,'确定')}`,
    cancelText:`${getLabel(31129,'取消')}`,
    onOk: () => func && func(),
  })
}

//用于获取高级搜索中的表单控件
export const getSearchs = (form, datas, needTigger = true, col=1, onEnterSearch) => {
  const {isFormInit} = form;
  let group = [];
  const formParams = form.getFormParams();
  isFormInit && datas && datas.map((c, _index) =>{
    let items = [];
    c.items.map(fields => {
      items.push({
        com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@gjeq4r@${fields.domkey[0]}`}
          label={`${fields.label}`}
          labelCol={{span: fields.labelcol}}
          wrapperCol={{span: fields.fieldcol}}>
          <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@2jkmq3@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={formParams} onEnterSearch={() => {
            typeof onEnterSearch === 'function' && onEnterSearch();
          }}/>
        </WeaFormItem>),
        colSpan:1
      })
    });
    if(needTigger){
      group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@4m3q95@${_index}`} col={col} needTigger={needTigger} title={c.title} showGroup={c.defaultshow} items={items}/>)
    }else {
      group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@m73qeq@${_index}`} col={col} needTigger={needTigger} showGroup={c.defaultshow} items={items}/>)
    }
  });
  return group;
}